package com.luoxiang.socialandroid.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.bean.Withdraw;
import com.luoxiang.socialandroid.utils.MmkvUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @systemUser Administrator
 * @Author LX
 * @Date 09-28-2022 周三 15:50
 */
public class JifentixianAdapter extends RecyclerView.Adapter<JifentixianAdapter.ViewHolder> {
    private List<Withdraw> list = new ArrayList<>();
    private int rowindex = -1;

    public JifentixianAdapter(List<Withdraw> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.adapter_tixian, parent, false);
        JifentixianAdapter.ViewHolder holder = new JifentixianAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.coincount.setText(list.get(position).getAmount() + holder.coincount.getContext().getString(R.string.mi_yuan));
        holder.renminbicoin.setText(list.get(position).getCredit() + holder.renminbicoin.getContext().getString(R.string.mi_jifen));
        holder.rl_taocanneirong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rowindex = position;
                MmkvUtil.INSTANCE.encode("positionid", list.get(position).getId());
                notifyDataSetChanged();
            }
        });
        if (rowindex == position) {
            holder.rl_taocanneirong.setBackgroundResource(R.drawable.shape_backblue);
            holder.renminbicoin.setTextColor(Color.parseColor("#835DFF"));
        } else {
            holder.rl_taocanneirong.setBackgroundResource(R.drawable.shape_itembuycoin);
            holder.renminbicoin.setTextColor(Color.parseColor("#666666"));
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView coincount, renminbicoin;
        RelativeLayout rl_taocanneirong;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            coincount = itemView.findViewById(R.id.coincount);
            renminbicoin = itemView.findViewById(R.id.renminbicoin);
            rl_taocanneirong = itemView.findViewById(R.id.rl_taocanneirong);
        }
    }

}
